<?php
/**
 * Created by PhpStorm.
 * User: 12133
 * Date: 2024/10/9
 * Time: 10:23
 */

namespace app\controller\index;
use app\model\Config;
use app\model\index\UserSearchKeyword AS model;

class History extends Base
{
    public function keyword(){
        $where = [];
        $nickname = input('nickname');
        $keyword = input('keyword');
        !empty($nickname) && $where[] = ['username','like','%'.$nickname.'%'];
        !empty($keyword) && $where[] = ['keyword','like','%'.$keyword.'%'];
        $list = model::where($where)
            ->with(['keywords'])
            ->order('update_time DESC')
            ->paginate(['page' => $this->page,'list_rows' => $this->size]);
        foreach ($list AS $key => $value){
            if (empty($value->keywords) || empty($value->keywords->price)) {
                unset($list[$key]);
                continue;
            }
            $dicount = \app\model\index\User::where('id',$value['user_id'])->value('price_ratio');
            $list[$key]['price'] = ceil($value->keywords->price * $dicount / 100)*100;
            if ($value['area_type'] == '抖音' || $value['area_type'] == 'douyin')
                $list[$key]['price'] = ceil($list[$key]['price'] * Config::get_value('douyin') / 100)*100;
            else
                $list[$key]['price'] = floor($list[$key]['price']);
        }
        return $this->view('/index/history/keyword',['list' => $list]);
    }
}